home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12096 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.inc.net!news
  2. From: Will Flor <willf@rrgroup.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Storing C Functions In An Array?
  5. Date: 28 Mar 1996 16:32:39 GMT
  6. Organization: R R Systems Group Inc.
  7. Message-ID: <4jeev7$7vf@news.inc.net>
  8. References: <4jc1u7$5e9@infa.central.susx.ac.uk>
  9. NNTP-Posting-Host: 204.95.173.139
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.2N (Windows; I; 32bit)
  14.  
  15. tepd6@central.susx.ac.uk (George Rattray) wrote:
  16. >Can someone help me, I'm trying to store functions in an array at
  17. >compile time. The following functions are defined as
  18. >
  19. >    struct complex func(struct complex, CHNL);
  20. >
  21. >I want to store them in an array ch[N];
  22. >
  23. >Therefor using the function with an index as 
  24. >
  25. >    ret = ch[0](x,chnl);
  26. >
  27. >Any help will be most appreciated, Thanks
  28. >
  29. >George
  30. >
  31.  
  32. You should store pointers to the functions, as I assume you know. Declare the
  33. array to be one of pointers to functions and assign using the common static
  34. "compile-time" array initialization, like so:
  35.  
  36.  struct complex (*ch[])(struct complex, CHNL) = { func1, func2, ... funcn }
  37.  
  38. It's been a while since I wrote any code that did this, but I'm pretty sure this will 
  39. work.
  40.  
  41. -Will Flor    willf@rrgroup.com
  42. The R R Systems Group, Inc.   http://www.rrgroup.com/
  43.  
  44.  
  45.